/*******************************************************************************
 * Copyright (c) 2013 Zero Square LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Zero Square LLC. Version 1
 * which accompanies this distribution
 ******************************************************************************/
package com.zsqr.dashboard.domain;
import javax.persistence.Id;
import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Table;

import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import javax.xml.bind.annotation.XmlRootElement;



/**
 * Entity to hold application user data - First Name,Last Name etc.
 * @author Saurabh
 *
 */
@XmlRootElement
@Entity
@Table(name="appuser")
public class UserEntity implements Serializable{
	
	private static final long serialVersionUID = -5950443841366553592L;
	@Id
	private int id;
	private String userName;
	private String firstName;
	private String lastName;
	private String passCode;
	
	//private long Id;
	
	private String password;
	
	public String getFirstName() {
		return firstName;
	}
	
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	public String getLastName() {
		return lastName;
	}
	
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	public String getUserName() {
		return userName;
	}
	
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		
		//For Desktop application password will be less then 20 char
		//and will have md5 encryption for IOS already encrypted pwd
		//will come so length will be > 20 char (TBD single method)
		
		int pLength = password.length();
		
		if (pLength < 20){
			PasswordEncoder crypto = new Md5PasswordEncoder();
	        this.password = crypto.encodePassword(password, null);
		}
		else{
			this.password = password;
		}
		
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public String getPassCode() {
		return passCode;
	}

	public void setPassCode(String passCode) {
		this.passCode = passCode;
	}

	//public long getId() {
	//	return Id;
	//}

	//public void setId(long id) {
	//	this.Id = id;
	//}

}
